<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>spect :: Functions (k-Wave)</title>
	<link rel="stylesheet" href="kwavehelpstyle.css" type="text/css">
</head>

<body>
<div class="content">

<h1>spect</h1>
<p class="purpose">Compute the single sided amplitude and phase spectrums.</p>

<h2>Syntax</h2>

<pre class="codeinput">
func_as = spect(func, Fs)
func_as = spect(func, Fs, ...)
[f, func_as] = spect(func, Fs)
[f, func_as] = spect(func, Fs, ...)
[f, func_as, func_ps] = spect(func, Fs)
[f, func_as, func_ps] = spect(func, Fs, ...)
</pre>

<h2>Description</h2>
<p><code>spect</code> computes the single-sided amplitude and phase spectrums of a 1, 2, or 3 dimensional input signal. If the optional input <code>'Dim'</code> is not specified, the spectrum is computed along the first non-singleton dimension. For example, running the commands</p>

<pre class="codeinput">
<span class="comment">% define signal</span>
Fs = 10e6;              <span class="comment">% [Hz]</span>
dt = 1 / Fs;            <span class="comment">% [s]</span>
t = 0:dt:(1000 * dt);   <span class="comment">% [s]</span>
signal = 10 * sin(0.5e6 * 2 * pi * t) + 5 * sin(1e6 * 2 * pi * t) + 2 * sin(2.5e6 * 2 * pi * t);

<span class="comment">% calculate spectrum</span>
spect(signal, Fs, 'Plot', [true, false]);
</pre>

<p>will produce the following amplitude spectrum.</p>

<img vspace="5" hspace="5" src="images/spect_01.png" style="width:560px;height:420px;" alt="">

<h2>Inputs</h2>

<table class="body">
    <tr valign="top">
        <td width = "150"><code>func</code></td>
        <td>signal to analyse</td>
    </tr>     
    
    <tr valign="top">
        <td><code>Fs</code></td>
        <td>sampling frequency [Hz]</td>
    </tr>  
</table>

<h2>Optional Inputs</h2>

<p>Optional 'string', value pairs that may be used to modify the default computational settings.</p>

<table cellspacing="0" class="body" cellpadding="4" border="2">
    <colgroup>
        <col width="18%"><col width="18%"><col width="18%"><col width="46%">
    </colgroup>
    
    <thead>
        <tr valign="top">
            <th bgcolor="#B2B2B2">Input</th>
            <th bgcolor="#B2B2B2">Valid Settings</th>
            <th bgcolor="#B2B2B2">Default</th>
            <th bgcolor="#B2B2B2">Description</th>
        </tr>
    </thead>
    
    <tbody>
		<tr valign="top">
            <td bgcolor="#F2F2F2"><code>'Dim'</code></td>
            <td bgcolor="#F2F2F2"><em>(integer scalar)</em></td>
            <td bgcolor="#F2F2F2"><em>first non-singleton dimension</em></td>            
            <td bgcolor="#F2F2F2">Dimension over which the spectrum is computed.</td>
        </tr>      
    
        <tr valign="top">
            <td bgcolor="#F2F2F2"><code>'FFTLength'</code></td>
            <td bgcolor="#F2F2F2"><em>(integer scalar)</em></td>
            <td bgcolor="#F2F2F2"><em>signal length</em></td>            
            <td bgcolor="#F2F2F2">Length of the FFT. If the set length is larger than the signal length, the signal is zero padded. If the set length is smaller than the signal length, the default value is used instead.</td>
        </tr>   

        <tr valign="top">
            <td bgcolor="#F2F2F2"><code>'PowerTwo'</code></td>
            <td bgcolor="#F2F2F2"><em>(Boolean scalar)</em></td>
            <td bgcolor="#F2F2F2"><code>false</code></td>            
            <td bgcolor="#F2F2F2">Boolean controlling whether the FFT length is forced to be the next highest power of 2.</td>
        </tr>     
        
        <tr valign="top">
            <td bgcolor="#F2F2F2"><code>'Plot'</code></td>
            <td bgcolor="#F2F2F2"><em>(Boolean scalar or two element vector)</em></td>
            <td bgcolor="#F2F2F2"><code>false</code></td>            
            <td bgcolor="#F2F2F2">Boolean controlling whether the amplitude and phase spectrums are plotted. Can be given as a two element array to control the display of the amplitude and phase spectrums, respectively.</td>
        </tr>         
               
        <tr valign="top">
            <td bgcolor="#F2F2F2"><code>'Unwrap'</code></td>
            <td bgcolor="#F2F2F2"><em>(Boolean scalar)</em></td>
            <td bgcolor="#F2F2F2"><code>false</code></td>            
            <td bgcolor="#F2F2F2">Boolean controlling whether the phase spectrum is unwrapped.</td>
        </tr>         
        
        <tr valign="top">
            <td bgcolor="#F2F2F2"><code>'Window'</code></td>
            <td bgcolor="#F2F2F2"><em>(string)</em></td>
            <td bgcolor="#F2F2F2"><code>'Rectangular'</code></td>            
            <td bgcolor="#F2F2F2">Parameter string controlling the window type used to filter the signal before the FFT is taken. Any valid input types for <code><a href="getWin.html">getWin</a></code> may be used.</td>
        </tr>        
    </tbody>
</table>

<h2>Outputs</h2>

<table class="body">
    <tr valign="top">
        <td width = "150"><code>f</code></td>
        <td>frequency array</td>
    </tr>
    
    <tr valign="top">
        <td><code>func_as</code></td>
        <td>single sided amplitude spectrum</td>
    </tr>    
    
    <tr valign="top">
        <td><code>func_ps</code></td>
        <td>single sided phase spectrum</td>
    </tr>      
</table>

<h2>Examples</h2>
<ul>
	<li><a href="example_ivp_sensor_frequency_response.html">Defining A Gaussian Sensor Frequency Response</a></li> 
	<li><a href="example_tvsp_doppler_effect.html">The Doppler Effect</a></li> 
	<li><a href="example_na_filtering.html">Filtering A Delta Function Input Signal</a></li>
	<li><a href="example_pr_2D_tr_absorption_compensation.html">Image Reconstruction With Compensation For Acoustic Absorption</a></li> 
	<li><a href="example_na_source_smoothing.html">Source Smoothing</a></li> 
	<li><a href="example_na_filtering.html">Filtering A Delta Function Input Signal</a></li> 
	<li><a href="example_na_modelling_absorption.html">Modelling Power Law Absorption</a></li>
</ul>

<h2>See Also</h2>

<code><a href="smooth.html">smooth</a></code>, <code><a href="filterTimeSeries.html">filterTimeSeries</a></code>

</div></body></html>